#ifndef GPU_HANDLER_H
#define GPU_HANDLER_H

#include <glew.h>
#include <string>
#include <Cg/cgGL.h>
#include <vector>
#include <glut.h>

#pragma comment(lib,"cgGL.lib")
#pragma comment(lib,"cg.lib")
#pragma comment(lib,"glew32.lib")

using namespace std;

#define READ	0
#define WRITE	1

typedef enum
{
	CG_GL_MODELVIEW_MTX,
	CG_GL_MODELVIEW_PROJECTION_MTX,
	CG_GL_MODELVIEW_IT_MTX,
	CG_GL_ARBITRARY_MTX,
	CG_GL_VECTOR_1D,
	CG_GL_VECTOR_2D,
	CG_GL_VECTOR_3D,
	CG_GL_VECTOR_4D,
	CG_GL_TEXTURE_2D,
	CG_GL_TEXTURE_RECT,
	CG_GL_TEXTURE_CUBE_MAP,
	CG_GL_VECTOR_4D_ARRAY,
} CGGL_PARAMETER_TYPE;

typedef struct  
{
	CGparameter	param;
	string		name;
	void		*ptrs;
	CGGL_PARAMETER_TYPE type;
}GPUParam;

typedef struct  
{
	GLenum target;
	GLenum interFormat;
	GLenum format;
	GLuint type;
	int width;
	int height;
	GLuint ID;
	GLuint texList[2];	
}GPUFBO;

typedef vector<GPUParam> GPUParamList;

class GPU_Handler
{
public:
	GPU_Handler(void);
	~GPU_Handler(void);

	void	SetShaderType(CGGLenum type);
	bool	Load(const char *filename, CGGLenum type);
	void	Unload();
	void	AddParameter(char *name, CGGL_PARAMETER_TYPE type, void *ptr);
	void	RefreshParameter();
	void	ShaderBind();
	void	ShaderRelease();

	void    SetUpFBO(int width, int height, GLenum interFormat, GLenum format, GLuint type, GLenum target=GL_TEXTURE_RECTANGLE_ARB);
	void	InitTexBuffer(char *name, float *read, float *write=NULL);
	void	FBOActivate();
	void	FBODeactivate();

	void	Swap();

	void	GPUCompute();


public:

	CGcontext					shaderContext;
	CGprogram					shaderProgram;
	CGprofile					shaderProfile;

	string shaderName;
	CGGLenum shaderType;

	GPUParamList				shaderParameters;
	GPUFBO						framebuffer;

};

#endif

